package cn.mrlong.mdialogstyle;

import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import cn.mrlong.mdialogstyle.dialog.AlertDateATimeDialog;
import cn.mrlong.mdialogstyle.dialog.AlertInputTextDialog;
import cn.mrlong.mdialogstyle.dialog.AlertSheetDialog;
import cn.mrlong.mdialogstyle.dialog.CircularProgressDialog;
import cn.mrlong.mdialogstyle.dialog.AlertDialog;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button btn = findViewById(R.id.btn_loading);
        Button btn_sure = findViewById(R.id.btn_sure);
        Button btn_cancel = findViewById(R.id.btn_cancel);
        Button btn_sheet = findViewById(R.id.btn_sheet);
        Button btn_input = findViewById(R.id.btn_input);
        Button btn_date_time = findViewById(R.id.btn_date_time);
        Button btn_loading_cancel = findViewById(R.id.btn_loading_cancel);
        btn.setOnClickListener(this);
        btn_loading_cancel.setOnClickListener(this);
        btn_sure.setOnClickListener(this);
        btn_cancel.setOnClickListener(this);
        btn_sheet.setOnClickListener(this);
        btn_input.setOnClickListener(this);
        btn_date_time.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {

            case R.id.btn_date_time:
                //显示日期时间
                new AlertDateATimeDialog(this,true,true).builder()
                        .setPostClickListener(new AlertDateATimeDialog.PostClickListener() {
                            @Override
                            public void onClick(String dateAndTime,String string) {
                                showMsg(string);
                            }
                        })
                        .setMaxDate(System.currentTimeMillis()-1000L)
                        .setDelimiter("/")
                        //.setTitle("这里是标题")
                        .show();
                break;
            case R.id.btn_input:
                //显示带输入框的Dialog
                new AlertInputTextDialog(this).builder()
                        .setTitle("请输入用户名")
                        .setMsgHint("请输入用户名")
                        .setCancelBtn("取消", new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {

                            }
                        })
                        .setPostBtn("确定", new AlertInputTextDialog.PostClickListener() {
                            @Override
                            public void onClick(String content) {
                                showMsg(content);
                            }
                        })
                        .show();
                break;
            case R.id.btn_sheet:
                //选择相机、相册的Dialog
                List<String> data = new ArrayList<>();
                data.add("相机");
                data.add("相册");
                new AlertSheetDialog(this)
                        .builder()
                        //.setTitle("sheet")
                        .setItemClickListener(new AlertSheetDialog.OnSheetItemClickListener() {
                            @Override
                            public void onClick(int which) {
                                showMsg(which + "");
                            }
                        })
                        .setItemTextColor(Color.BLACK)
                        .addItem(data)
                        .show();
                break;
            case R.id.btn_loading:
                //显示加载进度的Dialog
                CircularProgressDialog circularProgressDialog = new CircularProgressDialog(this);
                circularProgressDialog.show();
                //circularProgressDialog.setHintText("加载中...");
                break;
            case R.id.btn_loading_cancel:
                //显示加载进度的Dialog，可以通过按钮取消
                CircularProgressDialog circularProgressDialog2 = new CircularProgressDialog(this, new CircularProgressDialog.CancelOnClickListener() {
                    @Override
                    public void cancel() {
                        Toast.makeText(MainActivity.this,"取消啦",Toast.LENGTH_SHORT).show();
                    }
                });
                circularProgressDialog2.show();
                //circularProgressDialog.setHintText("加载中...");
                break;
            case R.id.btn_sure:
                //提示类容
                new AlertDialog(this)
                        .builder()
                        .setMsg("提示内容")
                        .setPostBtn("确定", new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                showMsg("点击");
                            }
                        }).show();
                break;
            case R.id.btn_cancel:
                //提示内容 带取消按钮的
                new AlertDialog(this)
                        .builder()
                        .setMsg("提示内容")
                        .setTitle("")
                        .setCancelBtn("取消", new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                showMsg("取消");
                            }
                        })
                        .setPostBtn("确定", new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                showMsg("点击");
                            }
                        }).show();
                break;
        }
    }

    private void showMsg(String msg) {
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
    }
}
